<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Cooperative\TaskAuditIndexRequest;
use App\Request\Cooperative\TaskIndexRequest;
use App\Request\Cooperative\TaskNotAllowRequest;
use App\Service\Cooperative\TaskService;
use Hyperf\Di\Annotation\Inject;

class TaskController extends AbstractController
{

    /**
     * @Inject()
     * @var TaskService
     */
    protected $taskService;

    /**
     * @OperationLog(event="获取任务管理列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index(TaskIndexRequest $request)
    {
        $where = $request->validated();
        $index = $this->taskService->index($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="获取任务审核列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function auditIndex(TaskAuditIndexRequest $request)
    {
        $where = $request->validated();
        $index = $this->taskService->index($where);
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="任务审核-通过",platform="cooperative")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Throwable
     */
    public function allow(int $taskId)
    {
        $data = $this->taskService->allow($taskId);
        return $this->response->success($data);
    }

    /**
     * @OperationLog(event="任务审核-不通过",platform="cooperative")
     * @param int $taskId
     * @param TaskNotAllowRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function notAllow(int $taskId, TaskNotAllowRequest $request)
    {
        $validated = $request->validated();
        $data = $this->taskService->notAllow($taskId, $validated['message']);
        return $this->response->success($data);
    }

    /**
     * @OperationLog(event="任务管理-冻结",platform="cooperative")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function block(int $taskId)
    {
        $data = $this->taskService->block($taskId);
        return $this->response->success($data);
    }

    /**
     * @OperationLog(event="任务管理-解冻",platform="cooperative")
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function unblock(int $taskId)
    {
        $data = $this->taskService->unblock($taskId);
        return $this->response->success($data);
    }

    /**
     * 任务详情
     * @param int $taskId
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function taskInfo(int $taskId)
    {
        $task = $this->taskService->taskInfo($taskId);
        return $this->response->success($task);
    }

}